let express = require("express");
let bodyParser = require("body-parser")
let fs = require("fs");
let web = express();
web.use(express.static("public"));
web.use(bodyParser.urlencoded({extended:true}))
web.get("/hot/move",(req,res)=>{
    fs.readFile("./data/hotMove.json",'utf-8',(err,data)=>{
        if(err){
            res.send("请求失败")
        }else{
            data = JSON.parse(data);
            res.send(data)
        }
    })
})

web.get("/get/user",(req,res)=>{
    // 获取前端传递的参数
    let {username,age,sex,phone} = req.query;
    res.send({code:0,msg:`欢迎光临${username}--${age}---${sex}---${phone}`})
})

web.post("/login",(req,res)=>{
    res.send({code:0,msg:"登录成功"})
})

web.post("/user/login",(req,res)=>{
    // 获取post请求传递的参数 req.body
    let {username,password} = req.body;
    res.send({
        code:0,
        msg:`登录成功${username}---${password}`
    })
})
web.listen(8080,()=>{
    console.log("服务端已启动.....")
})